<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">

    <ui:composition template="layout.xhtml">
        <ui:define name="body">
            <h:form id="userForm" enctype="multipart/form-data">
                <br/>
                <h2 class="title">Pesquisando Memorial Descritivo</h2>
                <p:growl id="messages" showDetail="true" autoUpdate="true"  /> 
                <div class="row">
                    <div class="twelve columns"> 
                        <br/>
                        <h4 class="title">Fator de Localização</h4>
                        <p:panel id="fatorPanel" style="background: none; border: none;" 
                                 styleClass="container_24 clearfix">
                            <p:outputLabel value="Distrito:" styleClass="grid_3" for="dInput" />
                            <p:inputText id="dInput" styleClass="grid_4" 
                                         value="#{managerMemorialDescritivo.imovel.inscricaoCadastralD}" />

                            <p:outputLabel value="Setor:" styleClass="grid_3" for="sInput" />
                            <p:inputText id="sInput" styleClass="grid_4" 
                                         value="#{managerMemorialDescritivo.imovel.inscricaoCadastralS}" />

                            <p:outputLabel value="Quadra:" styleClass="grid_3" for="qInput" />
                            <p:inputText id="qInput" styleClass="grid_4" 
                                         value="#{managerMemorialDescritivo.imovel.inscricaoCadastralQuadra}" />
                            <div class="clear-both" />

                            <p:outputLabel value="Lote:" styleClass="grid_3" for="lInput" />
                            <p:inputText id="lInput" styleClass="grid_4" 
                                         value="#{managerMemorialDescritivo.imovel.inscricaoCadastralLote}" />

                            <p:outputLabel value="Unidade:" styleClass="grid_3" for="uInput" />
                            <p:inputText id="uInput" styleClass="grid_4" 
                                         value="#{managerMemorialDescritivo.imovel.inscricaoCadastralUnid}" />
                            <div class="clear-both" />
                        </p:panel>
                        <h4 class="title">Proprietário</h4>
                        <p:panel id="ownerPanel" style="background: none; border: none;" 
                                 styleClass="container_24 clearfix ">

                            <!--                                <p:outputLabel id="personOutputLabel" value="Pessoa:" 
                                                                           for="personRadioButton"
                                                                           styleClass="grid_3" style="top: 6px" />
                                                            <div class="grid_8">
                                                                <p:selectOneRadio id="personRadioButton" 
                                                                                  value="  {managerSearchRealty.owner.typeDocument}" >
                                                                    <f:selectItems value="{managerSearchRealty.typeDocumentList()}" />
                                                                    <p:ajax event="change" update=":userForm:ownerPanel" />
                                                                </p:selectOneRadio>
                                                            </div>
                                                            <div class="clear-both" />
                                                            
                                                            <p:outputLabel value={managerSearchRealty.owner.typeDocument.type eq 'CPF' ? 'CPF:' : 'CNPJ:'}" 
                                                                           styleClass="grid_3" for="cpfInputMask" />
                                                            <p:inputMask id="cpfInputMask" styleClass="grid_4" 
                                                                         mask="{managerSearchRealty.owner.typeDocument.type eq 'CPF' 
                                                                                 ? '999.999.999-99' : '99.999.999/9999-99'}"
                                                                         value="{managerSearchRealty.owner.typeDocument.type eq 'CPF' 
                                                                                  ? managerSearchRealty.owner.cpf : managerSearchRealty.owner.cnpj}" />
                                                            <div class="clear-both" />-->

                            <!--                                <p:outputLabel value="Proprietário:" styleClass="grid_3" for="ownerAutoComplete" />
                                                            <p:autoComplete id="ownerAutoComplete" styleClass="grid_20" dropdown="true" converter="peopleconverter"
                                                                            var="item" itemLabel="{item.name} {item.cpf}" 
                                                                            itemValue="{item}" value="{managerSearchRealty.owner}" 
                                                                            scrollHeight="200" forceSelection="true"
                                                                            completeMethod="{managerSearchRealty.autocompletePeople}" />-->



                            <p:outputLabel value="Proprietario: "  styleClass="grid_3"/>
                            <p:selectOneRadio id="typePerson" 
                                              value="#{managerMemorialDescritivo.proprietario.tipoDocumento}" >  
                                <f:selectItems value="#{managerMemorialDescritivo.tipoDocumento()}" />
                                <p:ajax event="change" update=":userForm:ownerPanel" 
                                        />
                            </p:selectOneRadio>

                            <div class="clear"/>

                            <p:outputLabel id="typeDocumentLabel" 
                                           value="#{managerMemorialDescritivo.proprietario.tipoDocumento}: " 
                                           styleClass="grid_3"/>

                            <p:inputMask id="typeDocumentInput" 
                                         value="#{managerMemorialDescritivo.proprietario.tipoDocumento.tipo eq 'CPF' ? 
                                                  managerMemorialDescritivo.proprietario.cpf : managerMemorialDescritivo.proprietario.cnpj}"
                                         mask="#{managerMemorialDescritivo.proprietario.tipoDocumento.tipo eq 'CPF' ? 
                                                 '999.999.999-99':'99.999.999/9999-99'}" 
                                         styleClass="grid_8" > 

                            </p:inputMask>
                            <div class="clear"/>
                            <p:outputLabel value="Nome: " styleClass="grid_3" for="nomeInputText" 
                                           rendered="#{managerMemorialDescritivo.proprietario.tipoDocumento.tipo eq 'CPF'}"/>
                            <p:inputText id="nomeInputText" styleClass="grid_20 ajustInput" 
                                         value="#{managerMemorialDescritivo.proprietario.nome}" 
                                         rendered="#{managerMemorialDescritivo.proprietario.tipoDocumento.tipo eq 'CPF'}" />

                            <p:outputLabel value="Fantasia: " styleClass="grid_3" for="nameFantasyInputText" 
                                           rendered="#{managerMemorialDescritivo.proprietario.tipoDocumento.tipo eq 'CNPJ'}" />
                            <p:inputText id="nameFantasyInputText" styleClass="grid_20 ajustInput"
                                         value="#{managerMemorialDescritivo.proprietario.nomeFantasia}" 
                                         rendered="#{managerMemorialDescritivo.proprietario.tipoDocumento.tipo eq 'CNPJ'}" />



                        </p:panel>

                        <h4 class="title">Endereço</h4>
                        <p:panel id="addressPanel" style="background: none; border: none;" 
                                 styleClass="container_24 clearfix ">
                            <p:outputLabel value="CEP:" styleClass="grid_3" for="cepInputMask" />
                            <p:inputMask id="cepInputMask" styleClass="grid_4" mask="99.999-999"
                                         value="#{managerMemorialDescritivo.endereco.cep}" />
                            <div class="clear-both" />

                            <p:outputLabel value="Logradouro:" styleClass="grid_3   " for="patioInputText" />
                            <p:inputText id="patioInputText" styleClass="grid_20"
                                         value="#{managerMemorialDescritivo.endereco.logradouro}" />

                            <p:outputLabel value="Bairro:" styleClass="grid_3" for="neighborhoodInputText" />
                            <p:inputText id="neighborhoodInputText" styleClass="grid_20"
                                         value="#{managerMemorialDescritivo.endereco.bairro}" />

                        </p:panel>


                        <br/>
                        <div class="buttonAction">
                            <p:commandButton id="bt_add" value="Pesquisar" icon="ui-icon-search"
                                             update="tableImovel"
                                             actionListener="#{managerMemorialDescritivo.searchImovel()}"
                                             styleClass="ui-priority-primary" />
                            <p:commandButton id="bt_clear" value="Limpar" icon="ui-icon-close"
                                             actionListener="#{managerImovel.clear()}"
                                             update="@form" />

                            <p:commandButton  
                                title="Imprimir" 
                                ajax="false" update="@form" process="@this"
                                onclick="this.form.target='_blank'"
                                actionListener="#{managerMemorialDescritivo.reportMemorialDescritivo()}"
                                value="Imprimir"/>
                        </div >

                        <p:blockUI id="BLOCK" block="resultPanel" trigger="bt_add" > 
                            <p:graphicImage value="media/images/ajax-loader.gif"/>
                        </p:blockUI> 
                        <p:blockUI id="BLOCK_CLEAR" block="resultPanel" trigger="bt_clear" > 
                            <p:graphicImage value="media/images/ajax-loader.gif"/>
                        </p:blockUI>
                    </div> 
                    <h4 class="title">Resultado</h4>
                    <p:panel id="resultPanel" style="background: none; border: none;" 
                             styleClass="container_24 clearfix ">

                        <p:dataTable id="tableImovel" var="item" value="#{managerMemorialDescritivo.imoveis}" 
                                     styleClass="grid_24" rowIndexVar="rowid"
                                     rowKey="#{item.id}" rows="5" paginator="true"  
                                     paginatorPosition="bottom" emptyMessage="Nenhum registro">  
                            <f:facet name="header">
                                Imóvel
                            </f:facet>
                            <p:column headerText="Ação" width="30">
                                <p:commandButton disabled="#{item.proprietarios.isEmpty()}" 
                                                 title="Imprimir"
                                                 ajax="false" update="@form"
                                                 onclick="this.form.target='_blank'"
                                                 actionListener="#{managerMemorialDescritivo.reportMemorial(item)}"
                                                 value="Imprimir"/>


                            </p:column>

                            <p:column headerText="Localização" width="150">  
                                <ui:repeat value="#{item.enderecoImovel}" var="i">
                                    <h:outputText value="Logradouro #{i.logradouro}, bairro #{i.bairro} "/>
                                </ui:repeat>
                            </p:column>
                            <p:column headerText="Proprietário" width="100">  
                                <ui:repeat value="#{item.proprietarios}" var="o">
                                    <h:outputText value="#{o.tipoDocumento eq 'CPF' ? o.nome : o.nomeFantasia}"/>
                                    <br/>
                                </ui:repeat>
                                <p:outputLabel style="color: red" value="Não Existe Proprietário" rendered="#{item.proprietarios.isEmpty()}" />                    
                            </p:column> 

                        </p:dataTable> 

                    </p:panel>


                    <!--                    <div class="buttonAction">
                                            <p:button value="Voltar" href="indexrealty.xhtml"
                                                      icon="ui-icon-arrowreturnthick-1-w"/>
                    
                                        </div>-->
                </div>
            </h:form>
        </ui:define>
    </ui:composition>

</html>
